package com.jinwei.qunguanjia.common.utils;

import com.jinwei.qunguanjia.common.core.domain.model.LoginTenant;

public class TenantContextUtils implements AutoCloseable {

    private static InheritableThreadLocal<LoginTenant> currentTenantThread = new InheritableThreadLocal<>();

    public static LoginTenant getCurrentTenant() {
        return currentTenantThread.get();
    }

    public static void setCurrentTenant(LoginTenant loginTenant) {
        currentTenantThread.set(loginTenant);
    }

    public static String getCurrentTenantId() {
        return getCurrentTenant().getTenantId();
    }

    @Override
    public void close() {
        currentTenantThread.remove();
    }
}